package com.jiaai.util;

import com.jiaai.auth.model.AccessUser;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * class_name:RequestUtils
 * describe:------------------>request, session工具类
 * create_user:张昉平
 * create_date:2018/2/23
 * create_time:9:58
 */
public class RequestUtils {

    public static HttpServletRequest getRequest(){
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    public static HttpSession getSession(){
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
    }

    public static AccessUser getUser(){
        Object object=getSession().getAttribute(ConstantUtils.ACCESS_USER);
        if(object==null){
            return  null;
        }else {
            return (AccessUser) object;
        }

    }
}
